import Vue from 'vue'
import VueRouter from 'vue-router'
import Footer from '../components/footer.vue'
import searchRes from '../views/searchRes/index.vue'
import Detail from '../views/detail/index.vue'
// import Cookies from 'js-cookie'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue'),
      footer: Footer
    }
  }, {
    path: '/kind',
    name: 'Kind',
    components: {
      default: () => import(/* webpackChunkName: "kind" */ '../views/kind/index.vue'),
      footer: Footer
    }
  }, {
    path: '/cart',
    name: 'Cart',
    components: {
      default: () => import(/* webpackChunkName: "cart" */ '../views/cart/index.vue')
      // footer: Footer
    }
  }, {
    path: '/my',
    name: 'My',
    components: {
      default: () => import(/* webpackChunkName: "my" */ '../views/my/index.vue'),
      footer: Footer
    }
  },
  {
    path: '/order',
    name: 'order',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/order/index.vue')
    }
  },
  {
    path: '/orderDetail/:id',
    name: 'orderDetail',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/orderDetail/index.vue')
    },
    props: {
      default: true
    }
  }, {
    // 在当前路由后面添加一个:id会将detail路由后进行数据的拼接
    // :id这名字自定义，定义什么名字前端路由接收到的就是什么名字
    path: '/detail/:id',
    // 不使用懒加载的情况下使用到组件需要自己引入组件
    component: Detail
    // 此时将detail作为一个根路由，用children数组可以放置多个的数据
  }, {
    path: '/address',
    name: 'address',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/address/index.vue')
    }
  }, {
    path: '/setAddress',
    name: 'setAddress',
    components: {
      default: () => import(/* webpackChunkName: "home" */ '../views/setAddress/index.vue')
    }
  }, {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    components: {
      default: () => import(/* webpackChunkName: "login" */ '../views/login/login.vue')
    }
  }, {
    path: '/register',
    name: 'register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    components: {
      default: () => import(/* webpackChunkName: "reginster" */ '../views/register/register.vue')
    }
  }, {
    path: '/search',
    name: 'search',
    components: {
      default: () => import(/* webpackChunkName: "my" */ '../views/search/index.vue')
    }
  }, {
    path: '/searchRes/:id',
    name: 'searchRes',
    component: searchRes,
    props: true
  }, {
    path: '/setuser',
    components: {
      default: () => import(/* webpackChunkName: "setuser" */ '../views/setuser/index.vue')
    }
    // beforeEnter (to, from, next) {
    //   if (Cookies.get('isLogin') === 'ok') {
    //     next()
    //   } else {
    //     next('/login t=' + to.path)
    //   }
    // }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
